package cn.softwin.controller.customer;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.softwin.pojo.CstCustomer;
import cn.softwin.pojo.CstCustomerDetail;
import cn.softwin.service.impl.CustumerServiceImpl;

/**
 * Description: 添加客户信息的servlet
 * Author: zhangxiangkai
 * Params:
 * ReturnType:
 * Time: 2021/2/18-20:41
 */
@WebServlet("/AddCustomerMessageServlet")
public class AddCustomerMessageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * Description: 无参构造方法
     * Author: zhangxiangkai
     * Params: []
     * ReturnType:
     * Time: 2021/2/18-17:15
     */
    public AddCustomerMessageServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * Description: Get请求的servlet方法
	 * Author: zhangxiangkai
	 * Params: [request, response]
	 * ReturnType: void
	 * Time: 2021/2/18-17:15
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * Description: Post请求的servlet方法
	 * Author: zhangxiangkai
	 * Params: [request, response]
	 * ReturnType: void
	 * Time: 2021/2/18-17:16
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");//客户端往服务端传输
		CstCustomer cstCustomer = new CstCustomer();
		CstCustomerDetail cstCustomerDetail = new CstCustomerDetail();
		String custname = request.getParameter("custName");
		cstCustomer.setCust_name(custname);
		String custSource=request.getParameter("custSource");
		cstCustomer.setCust_source(custSource);
		String custindustry=request.getParameter("custindustry");
		cstCustomer.setCust_industry(custindustry);
		String custlevel=request.getParameter("custlevel");
		cstCustomer.setCust_level(custlevel);
		String custPhone = request.getParameter("custPhone");
		cstCustomer.setCust_phone(custPhone);
		String custMobile = request.getParameter("custMobile");
		cstCustomer.setCust_mobile(custMobile);
		String custAddress = request.getParameter("custAddress");
		cstCustomerDetail.setCust_address(custAddress);
		Long custcapital = Long.valueOf(request.getParameter("custcapital"));
		cstCustomerDetail.setCust_capital(custcapital);
		String custAddressString = request.getParameter("custAddress");
		cstCustomerDetail.setCust_address(custAddress);
		String custZip = request.getParameter("custZip");
		cstCustomerDetail.setCust_zip(custZip);
		String custFax = request.getParameter("custFax");
		cstCustomerDetail.setCust_fax(custFax);
		String custWebsite = request.getParameter("custWebsite");
		cstCustomerDetail.setCust_website(custWebsite);
		String custpic = request.getSession().getServletContext().getRealPath("/");
		custpic = "D:/ddd";
		cstCustomerDetail.setCust_pic(custpic);
		String custbank = request.getParameter("custbank");
		cstCustomerDetail.setCust_bank(custbank);
		//提交到数据库
		CustumerServiceImpl custumerService = new CustumerServiceImpl();
		boolean flag1 = custumerService.addCustumerMessage(cstCustomer);
		boolean flag2 = custumerService.addCustumerDetailMessage(cstCustomerDetail);
		if(flag1 && flag2) {
			request.getRequestDispatcher("success.jsp").forward(request, response);
		}else {
		}
	}
}
